package com.elong.android.specialhouse.dialogutil;

import android.content.Context;
import android.view.View;

import com.elong.android.specialhouse.R;
import com.elong.framework.netmid.ElongRequest;

public class HttpErrorDialog extends BaseHttpDialog implements View.OnClickListener {
	private IHttpErrorConfirmListener errConfirmListener;
//	private static HttpErrorDialog mInstanse ;

	private HttpErrorDialog(Context context) {
		super(context);
		mainView.findViewById(R.id.dialog_positive_button).setOnClickListener(this);
		mainView.findViewById(R.id.dialog_negative_button).setOnClickListener(this);
	}

//	public static HttpErrorDialog getInstanse(Context context) {
//		if (mInstanse == null) {
//			synchronized (HttpErrorDialog.class) {
//				if (mInstanse == null) {
//					mInstanse = new HttpErrorDialog(context) ;
//				}
//			}
//		}
//		return mInstanse ;
//	}

	@Override
	public void setParentView() {
		parentViewId = R.layout.dialog_normal;
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		if (id == R.id.dialog_positive_button) {
			if (errConfirmListener != null) {
				errConfirmListener.onHttpErrorConfirm(request);
			}
			dismiss();
		} else if (id == R.id.dialog_negative_button) {
			dail();
			dismiss();
		} else {
		}
	}

	private void dail() {
		// TODO Auto-generated method stub

	}

	/**
	 * 设置确认按钮回调
	 * 
	 * @param errConfirmListener
	 */
	public void setErrConfirmListener(IHttpErrorConfirmListener errConfirmListener) {
		this.errConfirmListener = errConfirmListener;
	}

	/**
	 * 弹出确认对话框，没有拨号
	 * 
	 * @param context
	 * @param request
	 * @param ErrorMessage
	 * @param errConfirmListener
	 */
	public static void ShowConfirm(Context context, ElongRequest request, String ErrorMessage, IHttpErrorConfirmListener errConfirmListener) {
//		HttpErrorDialog dialog = getInstanse(context) ;
		HttpErrorDialog dialog = new HttpErrorDialog(context) ;
		if (dialog.isShowing()) {
			dialog.dismiss();
		}
		dialog.setErrConfirmListener(errConfirmListener);
		dialog.bindRequest(request);
		dialog.setMessage(ErrorMessage);
		dialog.setPositiveText("确定");
		dialog.show();
	}

	/**
	 * 弹出确认对话框，有拨号
	 * 
	 * @param context
	 * @param request
	 * @param ErrorMessage
	 * @param errConfirmListener
	 */
	public static void ShowConfirmWithDail(Context context, ElongRequest request, String ErrorMessage, IHttpErrorConfirmListener errConfirmListener) {
//		HttpErrorDialog dialog = getInstanse(context) ;
		HttpErrorDialog dialog = new HttpErrorDialog(context) ;
		if (dialog.isShowing()) {
			dialog.dismiss();
		}
		dialog.setErrConfirmListener(errConfirmListener);
		dialog.bindRequest(request);
		dialog.setMessage(ErrorMessage);
		dialog.setPositiveText("确定");
		dialog.setNegativeText("电话预定");
		dialog.show();
	}

}
